
<!--员工登录组件-->

<template>
  <div class="LoginDiv">
    <el-form :model="loginForm" :rules="loginRule" ref="loginForm" label-position="left">
      <el-form-item label="username">
        <el-input v-model="loginForm.username"></el-input>
      </el-form-item>
      <el-form-item label="password">
        <el-input v-model="loginForm.password"></el-input>
      </el-form-item>
      <el-form-item style="text-align: right">
        <el-button @click="submitLogin">sign in</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import role from "assets/role"
  export default {
    name: "NormalLogin",
    data(){
      return{
        loginRole: role.state,
        //用户名密码
        loginForm:{
          username:'',
          password:'',
        },
        //用户名密码输入规则
        loginRule: {
          userName: [
            { required: true, message: '请输入用户名', trigger: 'blur' }
          ],
          pwd: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ]
        },
      }
    },

    methods:{
      //提交登录表单
      async submitLogin(){
        /*let data = this.loginForm;*/
        let mydata = {
          name:this.loginForm.username,
          password:this.loginForm.password,
        };
        this.$axios.$post('/login',mydata).then((res)=>{
          console.log(res);
          /*普通员工*/
          if(res.type==='2'){
            role.setState(res.name,res.type);
            console.log(role.state.username);
            this.$axios.defaults.headers.common['token']=role.state.username;
            this.$router.push({path:'/Customer'})
          }else if(res.type==='1'){
            role.setState(res.name,res.type);
            console.log(role.state.username);
            this.$axios.defaults.headers.common['token']=role.state.username;
            this.$router.push({path:'/Customer'})
          }else{
            alert('登陆失败')
          }
        })
      },
      logintest(){
        this.$router.push({path:'/Customer'})
      }
    }
  }
</script>

<style scoped>

</style>

